<template>
  <div class="app-container">
    <div class="app-title">
      <span>信息功能控制</span>
    </div>
    <div class="filter-container">
      <el-row>
        <el-form
          ref="dataForm"
          :model="formData"
          label-position="right"
          label-width="100px"
          size="small"
        >
          <el-row />
          <div class="contentBorder" :style="'height : '+tableHeight+'px'">
            <div :style="'padding-top: '+(tableHeight*0.3) +'px'">
            
                是否校验附件：
                <el-switch
                  v-model="fileVerify"
                  inactive-text="关"
                  active-text="开">
                </el-switch><br><br><br>
             
                为0上传：
                <el-switch
                  v-model="zeroAble"
                  inactive-text="关"
                  active-text="开">
                </el-switch>
            
              <el-button
                size="small"
                class="filter-item move"
                :style="'margin-left: 10px ;margin-top: '+(tableHeight*0.3) +'px'"
                type="primary"
                :loading="toUpdateLoading"
                @click="toUpdate"
              >
                保存
              </el-button>
              
            </div>

          </div>
        </el-form>
        <el-button
                size="medium"
                class="filter-item move"
                :style="'margin-left: 10px ;margin-top: '+(tableHeight*0.3) +'px'"
                type="primary"
                :loading="deleteRedisLoading"
                @click="deleteRedis('generateSalary')"
              >
                解除生成工资数据执行锁
              </el-button>
            <el-button
                size="small"
                class="filter-item move"
                :style="'margin-left: 10px ;margin-top: '+(tableHeight*0.3) +'px'"
                type="primary"
                :loading="deleteRedisLoading"
                @click="deleteRedis('lunarKnot')"
              >
                解除月结执行锁
              </el-button>  
      </el-row>
    </div>
  </div>
</template>

<script>
import {
  getSalaryConfig,
  updataGetSalaryConfig,
  deleteRedis
} from '@/api/salaryFunctionController/salaryFunctionController'

export default {
  name: 'functionControl',
  data() {
    return {
      checkAccessory:false,
      tableHeight: null,
      listLoading: true,
      toUpdateLoading: false,
      zeroAble: '',
      fileVerify: '',
      formData: {
        configType: '',
        isAble: ''
      },
      deleteRedisLoading: false,
    }
  },
  created() {
    this.getList()
  },
  mounted() {
    this.getTbHeight()
  },
  beforeMount() {
    window.addEventListener('resize', this.getTbHeight)
  },
  methods: {
    // 获取table高度的方法
    getTbHeight() {
      this.tableHeight = window.innerHeight - 120
    },
    getList() {
      this.listLoading = true
      getSalaryConfig().then(response => {
      let responseValues = response.data
      if(responseValues instanceof Array){
          responseValues.forEach(element => {
          if(element.configType==="zeroAble"){
            
            if(element.isAble==='0'){
              this.zeroAble = false
            }else{
              this.zeroAble = true
            }
            
          }
            if(element.configType==="fileVerify"){
            //  this.fileVerify =this.formData[i].isAble
              if(element.isAble==='0'){
                this.fileVerify = false
              }else{
                this.fileVerify = true
              }
            }
          });
      }else{
        this.fileVerify = false
        this.zeroAble = false
      }
        this.listLoading = false
      })
    },
    handleFilter() {
      this.getList()
    },
    toUpdate() {
      this.$refs['dataForm'].validate(valid => {
       
        if (valid) {
        this.toUpdateLoading = true
        const postIds = []
        const current = {}
        current['fileVerify'] = this.fileVerify
        current['zeroAble'] = this.zeroAble
        postIds.push(current)
          updataGetSalaryConfig(postIds).then(response => {
            this.dialogFormVisible = false
            this.$message({
              showClose: true,
              message: '保存成功',
              type: 'success',
              duration: 4000
            })
            this.toUpdateLoading = false
            this.handleFilter()
          })
        }
      })
    },
    deleteRedis(val){
      const current = {}
        current['uuid'] = val
        this.deleteRedisLoading=true
      deleteRedis(current).then(response => {
            this.dialogFormVisible = false
            this.$message({
              showClose: true,
              message: '解锁成功',
              type: 'success',
              duration: 4000
            })
             
          })
          this.deleteRedisLoading=false
    }


  }
}
</script>

<style scoped lang="scss">
.left {
  margin-left: 100px;
}

.move {
  margin-top: 50px;
  margin-right: 50px;
}

.app-title {
  margin-bottom: 15px;
  height: 20px;
  border-bottom: 1px solid #dcdfe6;
}

.contentBorder {
  //box-shadow: 2px 2px 5px #e5e6eb;
  width: 90%;
  border: #a9eaa9 solid 1px;
  text-align: center;
  margin-left: 3%;

  .el-row:nth-child(1) {
    padding-top: 30px;

    .el-col:nth-child(1) {
      text-align: center;
    }

    .el-col:nth-child(3) {
      .el-input {
        margin-top: -10px;
      }
    }

    .el-col:nth-child(4) {
      text-align: right;
    }
  }

  .el-row:nth-child(2) {
    padding-top: 20px;
    padding-bottom: 30px;

    .el-col:nth-child(1) {
      text-align: right;
    }
  }

  .el-row:nth-child(3) {
    padding-top: 50px;
    padding-bottom: 30px;
    border-top: rgba(121, 121, 121, 1) solid 1px;

    .el-col:nth-child(1) {
      text-align: center;
    }

    .el-col:nth-child(3) {
      .el-input {
        margin-top: -10px;
        padding: 0px 5px 0px 10px;
      }
    }

    .el-col:nth-child(4) {
      text-align: right;
    }

  }
}
</style>
